package handler;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;


import data.Angajat;
import data.AngajatiData;
import data.Scoala;


public class SaveData {
	public void saveAngajati(AngajatiData angajati) throws IOException {
Integer count=0;
		FileOutputStream fout = new FileOutputStream("DateAngajati.dat");
		ObjectOutputStream sout = new ObjectOutputStream(fout);
		Count dimensiune = new Count();
		for (Scoala school:angajati.getListaScoli())
		for(Angajat angajat:school.getListaAngajati())
			count++;
		dimensiune.setNumarAngajati(count);
		sout.writeObject(dimensiune);
		sout.flush();
		for (Scoala school : angajati.getListaScoli())
			for (Angajat angajat: school.getListaAngajati())
			{
					sout.writeObject(angajat);
					sout.flush();
				}
		sout.close();
		fout.close();
	}

	public void saveAngajati(AngajatiData angajati, String name) throws IOException {
		Integer count=0;
		if(name.substring(name.length()-4).equals(".dat"))
		{}
		else name+=".dat";
	
		FileOutputStream fout = new FileOutputStream(name);
		ObjectOutputStream sout = new ObjectOutputStream(fout);
		Count dimensiune = new Count();
		for (Scoala school:angajati.getListaScoli())
		for(Angajat angajat:school.getListaAngajati())
			count++;
		dimensiune.setNumarAngajati(count);
		sout.writeObject(dimensiune);
		sout.flush();
		for (Scoala school : angajati.getListaScoli())
			for (Angajat angajat: school.getListaAngajati())
			{
					sout.writeObject(angajat);
					sout.flush();
				}
		sout.close();
		fout.close();
		
	}

}